package com.space.school.dao.impl;

import com.space.school.dao.MasterDao;
import com.space.school.domain.Master;
import com.space.school.utils.SpaceJDBCUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Date;

public class MasterDaoImpl implements MasterDao {

    private JdbcTemplate jdbcTemplate=new JdbcTemplate(SpaceJDBCUtils.getDataSource());


    @Override
    public void insert(Master master) {
        String sql="insert into order_master (order_id,buyer_name,buyer_phone,buyer_address,buyer_openid,order_amount,order_total,order_status,pay_status,create_time) values(?,?,?,?,?,?,?,?,?,?)";
        jdbcTemplate.update(sql,master.getOrder_id(),master.getBuyer_name(),master.getBuyer_phone(),master.getBuyer_address(),master.getBuyer_openid(),master.getOrder_amount(),master.getOrder_total(),master.getOrder_status(),master.getPay_status(),new Date());
    }

    @Override
    public void update(Master master) {
        String sql="update order_master Set buyer_name=?,buyer_phone=?,buyer_address=?,buyer_openid=?,order_status=?,pay_status=? where order_id=?";
        jdbcTemplate.update(sql,master.getBuyer_name(),master.getBuyer_phone(),master.getBuyer_address(),master.getBuyer_openid(),master.getOrder_status(),master.getPay_status(),master.getOrder_id());
    }

    @Override
    public void finished(String order_id) {
        String sql="update order_master Set order_status=1,pay_status=1 where order_id=?";
        jdbcTemplate.update(sql,order_id);
    }

    @Override
    public void finished_pay(String order_id) {
        String sql="update order_master Set pay_status=1 where order_id=?";
        jdbcTemplate.update(sql,order_id);
    }


}
